﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;

namespace G.MVVM
{
    public class ListBoxBindingUtil<T> : NotifyObject
    {
        private ObservableCollection<T> dataSource;
        /// <summary>
        /// 数据源
        /// </summary>
        public ObservableCollection<T> DataSource
        {
            get
            {
                return dataSource;
            }
            set
            {
                if (!object.ReferenceEquals(dataSource, value))
                {
                    dataSource = value;
                    this.NotifyPropertyChanged("DataSource");
                }
            }
        }

        private T selectItem;
        /// <summary>
        /// 选中项
        /// </summary>
        public T SelectedItem
        {
            get
            {
                return selectItem;
            }
            set
            {
                if (!object.Equals(selectItem, value))
                {
                    selectItem = value;
                    this.NotifyPropertyChanged("SelectedItem");
                    if (SelectedItemChanged != null)
                        SelectedItemChanged(this, EventArgs.Empty);
                }
            }
        }

        /// <summary>
        /// 选中项改变
        /// </summary>
        public event EventHandler SelectedItemChanged;
    }
}
